package com.xrit.quartz;

import com.xrit.constant.RedisMessageConstant;
import com.xrit.utils.QiNiuUtils;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * 定时清除图片的任务工作类
 */
public class CleanImgJob {

    @Autowired
    private JedisPool jedisPool;

    @Test
    public void doClean(){
        //1.获取jedis对象
        Jedis jedis = jedisPool.getResource();
        //2.获得差集
        Set<String> diff = jedis.sdiff(RedisMessageConstant.SETMEAL_PIC_RESOURCES, RedisMessageConstant.SETMEAL_PIC_DB_RESOURCES);
        //3.七牛云批量删除
        QiNiuUtils.removeFiles(diff.toArray(new String[]{}));
        //4.清除redis中保存的所有图片数据
        jedis.del(RedisMessageConstant.SETMEAL_PIC_RESOURCES, RedisMessageConstant.SETMEAL_PIC_DB_RESOURCES);
        jedis.close();
    }
}
